﻿//AcademicPlanner - course registration planning web app.
//Copyright (C) 2009  Boubacar Diallo

//This program is free software; you can redistribute it and/or
//modify it under the terms of the GNU General Public License
//as published by the Free Software Foundation; either version 2
//of the License, or (at your option) any later version.

//This program is distributed in the hope that it will be useful,
//but WITHOUT ANY WARRANTY; without even the implied warranty of
//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//GNU General Public License for more details.

//You should have received a copy of the GNU General Public License
//along with this program; if not, write to the Free Software
//Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.


using System;
using System.Collections.Generic;
using System.Linq;
using AcademicPlanner.Data;
using AcademicPlanner.Data.Entities;

namespace AcademicPlanner.Domain.Models
{
	/// <summary>
	/// Actor is the base class for all models in the AcademicPlanner
	/// application representing a participant in the system.
	/// </summary>
	/// <since>1.0</since>
	public abstract class Actor : Model
	{
		/// <summary>
		/// The <c>User</c> associated with this Actor.
		/// </summary>
		/// <since>1.0</since>
		protected User user;


		/// <summary>
		/// Gets the <c>User</c> associated with this Actor.
		/// </summary>
		/// <since>1.0</since>
		public User User 
		{
			get
			{
				if (user == null && ((ActorEntity)entity).UserEntity != null)
					user = DomainMaster.ModelsFountain.GetUser(((ActorEntity)entity).UserEntity);
				return user; 
			} 
		}


		internal Actor()
			: base()
		{

		}

		internal Actor(Entity pEntity)
			: base(pEntity)
		{
			
		}


		internal void InitUser(User pUser)
		{
			if (User == null)
			{
				((ActorEntity)entity).UserEntity = (UserEntity)GetOtherModelEntity(pUser);
			}
		}
    }
}
